//
//  QuanYiViewController.m
//  BaseProject
//
//  Created by 王洋 on 2021/1/23.
//  Copyright © 2021 王洋. All rights reserved.
//
#import "BA_PNGHeaderView.h"
#import "PackageDetailSectionHeader.h"

#import "QuanYiViewController.h"

@interface QuanYiViewController ()<UITableViewDelegate, UITableViewDataSource>


@property (nonatomic, strong) PackageDetailSectionHeader *headerView;

@end

@implementation QuanYiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self initView];
    });

}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
}

- (void)initView {
    

    //屏幕常亮
    [UIApplication sharedApplication].idleTimerDisabled = YES;
    self.navigationController.navigationBarHidden = YES;
    #if RT_INTERACTIVE_PUSH
        self.rt_navigationController.rt_enableInteractivePush = YES;
    #endif
    
    if([self.tableview respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) {
        if (@available(iOS 11.0, *)) {
            self.tableview.contentInsetAdjustmentBehavior=UIScrollViewContentInsetAdjustmentNever;
        } else {
            // Fallback on earlier versions
        }
    }
    
    [self.view addSubview:self.tableview];
    
    [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
        
    self.headerView =  [[NSBundle mainBundle] loadNibNamed:@"PackageDetailSectionHeader"owner:nil options:nil].firstObject;
    self.headerView.frame = CGRectMake(0, 0, TTScreenWidth, 50);
    self.headerView.sectionTitleLab.text = @"平台权益";

    self.tableview.tableHeaderView = self.headerView;
    self.headerView.autoresizingMask = UIViewAutoresizingNone;
    
    [self.tableview reloadData];
}

#pragma mark UITableviewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 0;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    //return TTScreenWidth * 2.91466;
    CGSize size = [UIImage imageNamed:@"pingtaiquanyidetail"].size;
    return  size.height * kScreenWidth / size.width;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return CGFLOAT_MIN;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return CGFLOAT_MIN;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    BA_PNGHeaderView *headerView =  [[NSBundle mainBundle] loadNibNamed:@"BA_PNGHeaderView"owner:nil options:nil].firstObject;
    
//    [headerView.mainImageView
//     sd_setImageWithURL:[NSURL URLWithString:B_QUANYI_DETAIL]
//     placeholderImage:[UIImage imageNamed:@"pingtaiquanyidetail"]
//     options:SDWebImageProgressiveLoad];
    headerView.mainImageView.image = [UIImage imageNamed:@"pingtaiquanyidetail"];
    return headerView;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [UITableViewCell new];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    if (scrollView.contentOffset.y < -10) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"packageHideQuanYiNoti" object:nil userInfo:nil];
    }
}

- (UITableView *)tableview {
    if (!_tableview) {
        _tableview = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableview.backgroundColor =  UIColorHex(0xf1f1f1);

        _tableview.showsHorizontalScrollIndicator = NO;
        _tableview.showsVerticalScrollIndicator = NO;
        
        _tableview.estimatedSectionHeaderHeight = 0;
        _tableview.estimatedSectionFooterHeight = 0;
        _tableview.estimatedRowHeight = 0;
    }
    return _tableview;
}



@end
